# -*- coding: UTF-8 -*-
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
import time

driver = webdriver.Chrome()
driver.get('http://www.baidu.com')
driver.maximize_window()
size = driver.get_window_size()
print("页面高度为：",size['height'])

driver.find_element_by_id('kw').send_keys('深圳')
driver.find_element_by_id('su').click()
time.sleep(2)
driver.find_element_by_link_text('图片').click()
time.sleep(2)
img = driver.find_elements_by_css_selector('div.imgbox img[class="main_img img-hover"]')
print('一页加载的图片数：',len(img))

imgs = []
while len(imgs) < 50:
    driver.execute_script('window.scrollBy(0,1056)')
    imgs = WebDriverWait(driver,10,0.5).until(lambda x :x.find_elements_by_css_selector('div.imgbox img[class="main_img img-hover"]'))

imgs[49].click()
time.sleep(3)
driver.quit()